package com.quyeying.controller;

import com.quyeying.utils.result.R;
import com.quyeying.utils.result.ResultEnum;
import org.springframework.web.bind.annotation.*;
import com.quyeying.service.TblBusinessCategoryService;
import com.quyeying.entity.TblBusinessCategoryEntity;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RestController;

/**
* <p>
* tbl_business_category 前端控制器
* </p>
* @author jll
* @since 2022-12-14
*/
@Slf4j
@RestController
@RequestMapping("businessCategoryEntity")
public class TblBusinessCategoryController {

    @Resource
    private TblBusinessCategoryService tblBusinessCategoryService;

    /**
    * 新增
    **/
    @PostMapping("/add")
    public R add(@RequestBody TblBusinessCategoryEntity tblBusinessCategoryEntity){
        try {
            return tblBusinessCategoryService.add(tblBusinessCategoryEntity);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
    * 删除
    **/
    @DeleteMapping("/del")
    public R delete(Long id){
        try {
            return tblBusinessCategoryService.delete(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
    * 更新
    **/
    @PostMapping("/update")
    public R update(@RequestBody TblBusinessCategoryEntity tblBusinessCategoryEntity){
        try {
            return tblBusinessCategoryService.updateData(tblBusinessCategoryEntity);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
    * 分页查询
    **/
    @GetMapping("/findListByPage")
    public R findListByPage(@RequestParam Integer current,
    @RequestParam Integer size){
        try {
            return tblBusinessCategoryService.findListByPage(current, size);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }

    /**
    * id查询
    **/
    @GetMapping("/findById")
    public R findById(Long id){
        try {
            return tblBusinessCategoryService.findById(id);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 全部查询
     **/
    @GetMapping("/findList")
    public R findListByPage(){
        try {
            return tblBusinessCategoryService.findList();
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return R.error(ResultEnum.SYSTEM_ERROR);
        }
    }
}
